package cn.ustb.dao;

import cn.ustb.entity.StudentGrade;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface StudentGradeDao {
    @Select("select * from studentGrade")
    List<StudentGrade> getAll();

    @Select("SELECT * FROM studentGrade where studentId = #{parseLong}")
    List<StudentGrade> getAllCourseGrade(long parseLong);

    @Select({"<script>",
            "select * from studentGrade where studentId = #{studentId}",
            "<if test = \"yearTerm!=null\">"+
                    " and yearTerm like concat('%',concat(#{yearTerm},'%'))"+
                    " </if>",
            "</script>"
    })
    List<StudentGrade> getAllWithYearTerm(@Param("studentId") Long studentId, @Param("yearTerm") String yearTerm);

    @Insert("insert into studentgrade values(#{yearTerm},#{studentId},#{studentName},#{courseId},#{courseName},#{score},#{gradePoint},#{credit},#{courseClass},#{studyWay},#{examWay},#{gradeWay},#{effectivity},#{remarks})")
    void insert(StudentGrade studentGrade);

    @Select("select * from studentGrade where studentId = #{studentId} and courseId = #{courseId}")
    StudentGrade getStudentGrade(StudentGrade studentGrade);

    @Update("update studentgrade set score = #{score} where studentId = #{studentId} and courseId = #{courseId}")
    void update(StudentGrade studentGrade);

    @Select("SELECT * FROM studentGrade where studentId = #{parseLong} and studyWay = '必修'")
    List<StudentGrade> getBiXiuCourseGrade(long parseLong);

    @Select("SELECT * FROM studentGrade where studentId = #{parseLong} and studyWay = '选修'")
    List<StudentGrade> getXuanXiuCourseGrade(long parseLong);
}
